<?php
    $reportMember=$_SESSION["report"]["member"];
    if(count($reportMember)==0){
        include "report/selectMember/selectMember.php";
    }else{
        
        $temp="";
        if(is_array($reportMember)){
            foreach ($reportMember as $key => $value) {
                $temp.="'$key',";
            }
        }
        $temp=  substr($temp, 0,  strlen($temp)-1);

        ?>
<script type="text/javascript">
    function showGraph(){
        $.post('report/fertilizerProfitCompare/fertilizerProfitCompareGraph.php',
            $('#selectCropForm').serialize()
        ,function(data){
            $('#costProfitCompareGraph').html(data);
        });
    }
</script>
<table class="noSpacing" style="width: 100%;height: 100%;">
    <tr>
        <td style="padding: 5px;vertical-align: top;">
            <div id="selectCrop" class="box-wrap" style="display: table;margin-left: auto;margin-right: auto;width: 100%;">
                <div class="box-heading">
                    <h4>
                        <i class="icon-tag"></i> 
                        เลือก Crop
                    </h4>
                </div>
                <div class="box-inner" style="padding: 0px;">
                    <table class="noSpacing"style="width: 100%;height: 100%;">
                        <tr>
                            <td style="vertical-align: top;padding: 0px;">
                                <form id="selectCropForm">
                                    <table class="noSpacing" style="width: 100%;">
                                        <?php
                                            $query="
                                                select  *
                                                from    member_farm_crop
                                                where   farmID in (
                                                            select  farmID
                                                            from    member_farm
                                                            where   memID in (
                                                                        ".$temp."
                                                                    )
                                                        )
                                                ";
                                            $result=$mysqli->query($query);
                                            while($row=$result->fetch_array(MYSQLI_ASSOC)){
                                                $farmClass=new farm($row["farmID"]);
                                                $farm=$farmClass->getFarm();

                                                $memberClass=new member($farm["memID"]);
                                                $member=$memberClass->getMember();

                                                $dateClass=new date();

                                                ?>
                                        <tr class="hover" style="cursor: pointer;">
                                            <td style="padding: 10px;width: 10px;"><input id="checkbox<?=$row["cropID"]?>" name="cropID[]" type="checkbox" value="<?=$row["cropID"]?>"></td>
                                            <td style="padding: 5px;"
                                                onclick="
                                                    $('#checkbox<?=$row["cropID"]?>').click();
                                                    showGraph();
                                                "
                                                >
                                                <?=$member["firstName"]." ".$member["lastName"];?>
                                                <div style="float: right;font-size: 80%;"><?=$dateClass->dateEncodeBE($row["startDate"]);?></div>
                                            </td>
                                        </tr>
                                                    <?php
                                            }
                                        ?>
                                    </table>
                                </form>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <button type="button" style="position: fixed;top: 59px;right: 10px;z-index: 1000" class='btn btn-default'
                onclick="
                    $('#graphName').toggle();
                    $('#headerTR').toggle();
                    $('#selectCrop').toggle();
                    if($('#fullScreenIcon').attr('class')=='glyphicon glyphicon-resize-full'){
                        $('#fullScreenIcon').removeClass('glyphicon glyphicon-resize-full');
                        $('#fullScreenIcon').addClass('glyphicon glyphicon-resize-small');
                    }else{
                        $('#fullScreenIcon').removeClass('glyphicon glyphicon-resize-small');
                        $('#fullScreenIcon').addClass('glyphicon glyphicon-resize-full');
                    }
                "
                >
                <span id='fullScreenIcon' class='glyphicon glyphicon-resize-full'></span>
            </button>
            <div class="box-wrap" style="display: table;margin-left: auto;margin-right: auto;width: 100%;margin-top: 5px;">
                <div class="box-heading">
                    <h4>
                        <i class="icon-tag"></i> 
                        <span class="glyphicon glyphicon-signal"></span>
                        เปรียบเทียบต้นทุนปุ๋ย และรายได้เหนือต้นทุน
                    </h4>
                </div>
                <div id="costProfitCompareGraph" class="box-inner"></div>
            </div>
        </td>
    </tr>
</table>
<script type="text/javascript">
    showGraph();
</script>
            <?php
    }
?>